class Node {
  constructor(data) {
    this.data = data
    this.next = null
  }
}

class LinedList {
  constructor() {
    this.head = null
    this.size = 0
  }

  append(data) {
    let node = new Node(data)
    if(!this.head) {
      this.head = node
    }else {
      let current = this.head
      while(current.next)  {
       current = current.next
      }
      current.next = node
    }
    this.size++
  }

 appendAt(position,data) {
    let node = new Node(data)
    if(position===0) {
      node.next =  this.head
      this.head = node
    }else {
      let pre = this.getNode(position-1)
      node.next = pre.next
      pre.next = node
    }
  }
  getNode(index) {
    let current = this.head
     for(let i=0;i<index;i++) {
      current = current.next
    }
    return current
  }
}

let ll = new LinedList()
ll.append(1)
ll.append(2)
ll.append(3)
ll.appendAt(0,22)
ll.appendAt(1,33)
ll.appendAt(2,44)
console.dir(ll,{
  depth: 100
})
